<template>
  <div>
    <AplidForm v-model="formModel" @reset="onRest" @submit="onSubmit"
      v-bind="AppealHandleConfig(nowRowData.processingStatus)">
      <template v-slot:appeal_dataForm>
        <LogList :tableName="nowRowData.tableName" :changeType="nowRowData.changeType" :batchNumber="nowRowData.id">
        </LogList>
      </template>
      <template v-slot:appeal_materialForm>
        <el-descriptions :title="`申述数据批次号:${nowRowData.id}`" :column="1">
          <el-descriptions-item label="变更人">
            {{ nowData.changePerson }}
          </el-descriptions-item>
          <el-descriptions-item label="变更内容">
            {{ nowData.changeContent }}
          </el-descriptions-item>
          <el-descriptions-item label="变更时间">
            {{ nowData.changeDate }}
          </el-descriptions-item>
          <el-descriptions-item label="变更所属单位">
            {{ nowData.changePersonUnit }}
          </el-descriptions-item>
          <el-descriptions-item label="变更类型">
            {{ nowData.changeType }}
          </el-descriptions-item>
        </el-descriptions>
      </template>
      <template v-slot:appeal_contentForm>
        <el-card style="width: 100%">
          <p>
            <span class="mr8">情况说明:</span>
            <span>{{ nowData.changeDescription }}</span>
          </p>
          <div>
            <p>证明材料</p>
            <FileList :item="{ label: '文件' }" :value="changeMaterials">
            </FileList>
          </div>
        </el-card>
      </template>
      <template v-slot:flagResultForm>
        <el-descriptions :column="1">
          <el-descriptions-item label="处理日期">
            {{ nowData.processingDate }}
          </el-descriptions-item>
          <el-descriptions-item label="处理结果">
            <el-tag type="danger" effect="dark" v-if="nowData.processingResults == 0">驳回</el-tag>
            <el-tag type="success" effect="dark" v-if="nowData.processingResults == 1">通过</el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="驳回原因">
            {{ nowData.reasonsRejection }}
          </el-descriptions-item>
          <el-descriptions-item label="相关材料">
            <FileList :item="{ label: '文件' }" :value="nowData.rejectionMaterials"></FileList>
          </el-descriptions-item>
        </el-descriptions>
      </template>
    </AplidForm>
  </div>
</template>

<script setup lang="ts">
import { getStore } from '@/utils/store'
import { AppealHandleConfig } from '../config'
import LogList from '@/views/datacenter/components/DataGather/change/LogList.vue'
import apiMod from '@/apiMod'
import FileList from '@/views/aplid/DetailPage/ContentListItem/FileList/index.vue'

type Props = {
  nowRowData?: any
}

const props = withDefaults(defineProps<Props>(), {})
const emit = defineEmits(['refresh'])

let nowData: any = ref({})
const changeMaterials = ref([])
const formModel = ref({})
let multipleSelection = []
// 获取变更明细
const getInitData = () => {
  apiMod.view_dpDataChange_page({ id: props.nowRowData.id }).then((res) => {
    const data = res.data
    const dataItem = data.records[0] || {}
    nowData.value = dataItem
    const materialsData = dataItem.changeMaterials?.split(',') || []
    changeMaterials.value = materialsData
  })
}

// 提交审批- 进入工作流
const onSubmit = (form, done) => {
  const userInfo = getStore('userInfo') || {}
  apiMod
    .act_task_checkNew({
      ...form,
      user: {
        id: userInfo.id,
        username: userInfo.username,
      },
      successIds: multipleSelection.map((item) => item.id),
      processInstanceId: props.nowRowData.processInstanceId,
    })
    .then((res) => {
      emit('refresh')
      done()
    })
    .catch((err) => {
      done()
    })
}
const onRest = () => {
  emit('refresh')
}

onMounted(() => {
  getInitData()
})
</script>

<style scoped></style>
